package com.tiange.aop;

import com.tiange.annotation.MyAnno;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class MyAnnoAspect {

    @Pointcut("@annotation(com.tiange.annotation.MyAnno)")
    private void pointcut(){}

    @Around("pointcut()")
    public Object doWork(ProceedingJoinPoint point) throws Throwable {
        MethodSignature ms = (MethodSignature) point.getSignature();
        Method method = ms.getMethod();
        MyAnno myAnno = method.getAnnotation(MyAnno.class);
        System.out.println("before:"+method);
        Object obj = point.proceed();
        System.out.println("after:"+method);
        return obj;
    }
}
